/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javaseapp - T70
 * <p>Powered by webrx On 2021-08-27 09:22:16
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class T70 {
    volatile int num = 0;
    CountDownLatch latch = new CountDownLatch(100);

    void work() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ++num;
        latch.countDown();
    }

    void print() {
        System.out.println(num);
    }

    public static void main(String[] args) {
        var t = new T70();
        for (int i = 0; i < 100; i++) {
            new Thread(t::work, "T" + i).start();
        }

        try {
            t.latch.await();
            t.print();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
